# encoding: utf-8

class Hero(object):
    def __init__(self,name,hp,mp,attack,defence):
        self.name = name
        self.hp = hp
        self.mp = mp
        self.attack = attack
        self.defence = defence
        self._attack_all = attack
        self._defence_all = defence
        self.head = Blank()
        self.body = Blank()
        self.hand = Blank()
        self.leg = Blank()
        self.foot = Blank()
        self.weapon = Blank()
    
    def equip(self,obj):
        if isinstance(obj,EquipHead):
            return self.equip_head(obj)
        
    def equip_head(self,head):
        self.head = head
        return 1
    
    def unequip_head(self):
        self.head = Blank()
        return 1
    
    def equip_body(self,body):
        self.body = body
        return 1
    
    def unequip_body(self):
        self.head = Blank()
        return 1
    
    def equip_hand(self,hand):
        self.hand = hand
        return 1
    
    def unequip_hand(self):
        self.hand = Blank()
        return 1
    
    def equip_leg(self,leg):
        self.leg = leg
        return 1
    
    def unequip_leg(self):
        self.leg = Blank()
        return 1
    
    def equip_foot(self,foot):
        self.foot = foot
        return 1
    
    def unequip(self):
        self.foot = Blank()
        return 1
    
    def equip_weapon(self,weapon):
        self.weapon = weapon
        return 1
    
    def unequip_weapon(self):
        self.weapon = Blank()
        return 1
    
    @property
    def attack_all(self):
        return self.attack + self.head._attack + self.body._attack + \
            self.hand._attack + self.leg._attack + self.foot._attack + \
            self.weapon._attack
            
    @property
    def defence_all(self):
        return self.defence + self.hand._defence + self.body._defence + \
            self.hand._defence + self.leg._defence +self.foot._defence + \
            self.weapon._defence
        
    def over(self,enemy):
        if enemy.hp <= 0:
            return True
        
    def pk(self,enemy):
        enemy.hp = enemy.hp - (self.attack_all*2 - enemy.defence_all)
        if self.over(enemy):
            return '%s is over' % enemy.name
        else:
            return enemy.hp
    
    def __str__(self):
        return self.name

class Enemy(object):
    def __init__(self,name,hp,mp,attack,defence):
        self.name = name
        self.hp = hp
        self.mp = mp
        self.attack = attack
        self.defence = defence
        self.attack_all = attack
        self.defence_all = defence
        
    def over(self,hero):
        if hero.hp <= 0:
            return True    
        
    def pk(self,Hero):
        Hero.hp = Hero.hp - (self.attack_all*2 - Hero.defence_all)
        if self.over(Hero):
            return '%s is over' % Hero.name
        else:
            return Hero.hp
 
class Blank(object):
    def __getattribute__(self,name):
        return 0
    
class EquipHead(object):
    def __init__(self,name,attack,defence):
        self.name = name
        self._attack = attack
        self._defence = defence
    
class EquipBody(object):
    def __init__(self,name,attack,defence):
        self.name = name
        self._attack = attack
        self._defence = defence
        
class EquipHand(object):
    def __init__(self,name,attack,defence):
        self.name = name
        self._attack = attack
        self._defence = defence

class EquipLeg(object):
    def __init__(self,name,attack,defence):
        self.name = name
        self._attack = attack
        self._defence = defence
        
class EquipFoot(object):
    def __init__(self,name,attack,defence):
        self.name = name
        self._attack = attack
        self._defence = defence
        
class EquipWeapon(object):
    def __init__(self,name,attack,defence):
        self.name = name
        self._attack = attack
        self._defence = defence
    

        
